home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Incrementing enumerated types
- Date: Thu, 01 Feb 1996 16:13:20 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4eqoq2$bi5@news.halcyon.com>
- References: <Andy.Law-3101961138310001@pc0734.ri.bbsrc.ac.uk>
- NNTP-Posting-Host: blv-pm2-ip25.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Doubtless not legal because enum values needn't be consecutive.
- enum bleah { error=-1, empty, argle, bargle, targle=4, zargle=8 }.
-
- Use the enum where a programmer must read the code, like in switch
- statements, conditionals, intializations, but cast it to int in the
- for-loop (if you're positive it's values are consecutive, like indices
- into an array).
-
-
- Andy.Law@bbsrc.ac.uk (Andy Law) wrote:
-
- >Is it legal to increment an enumerated type? I have an enumerated list of
- >possible document types that I want to step through, and my compiler is
- >barfing on it. It seems such a waste of an enumeration if I have to resort
- >to ints to get this done.
-
- >Alternatively does anyone have a suggestion as to how to do this kind of
- >thing legally?
-
- >for (EnumeratedType eIndex = enum_first; eIndex < enum_last; eIndex++) {
- > ^^^^^^^^
- > /* do something */
- >}
-
- >TIA,
-
- >Andy Law
- >------------------
- >( Andy.Law@bbsrc.ac.uk )
- >( Big Nose in Edinburgh )
-
-
-